﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

namespace SWENAssignment.HuiYi
{
    public class HotelManagement
    {
        public static int InsertUserAccount(createUserAccount u)
        {
            int rowsinserted = 0;
            try
            {
                SqlConnection conn = new SqlConnection();
                conn.ConnectionString = ConfigurationManager.ConnectionStrings["HotelManagementConnectionString"].ConnectionString;
                conn.Open();

                SqlCommand comm = new SqlCommand();
                comm.Connection = conn;
                comm.CommandText = "Insert into userAccount (userType, loginID, password, confirmedPassword, lastName, firstName, dateOfBirth, contNum, mailAdd, email, gender, bankAccType, bankAccNum ) values (@userType, @loginID, @password, @confimedPassword, @lastName, @firstName, @dateOfBirth, @contNum, @mailAdd, @email, @gender, @bankAccType, @bankAccNum)";

                comm.Parameters.AddWithValue("@userType", u.UserType);
                comm.Parameters.AddWithValue("@loginID", u.LoginID);
                comm.Parameters.AddWithValue("@password", u.Password);
                comm.Parameters.AddWithValue("@confirmedPassword", u.ConfirmedPassword);
                comm.Parameters.AddWithValue("@lastName", u.LastName);
                comm.Parameters.AddWithValue("@firstName", u.FirstName);
                comm.Parameters.AddWithValue("@dateOfBirth", u.DateOfBirth);
                comm.Parameters.AddWithValue("@contNum", u.ContNum);
                comm.Parameters.AddWithValue("@mailAdd", u.MailAdd);
                comm.Parameters.AddWithValue("@email", u.Email);
                comm.Parameters.AddWithValue("@gender", u.Gender);
                comm.Parameters.AddWithValue("@bankAccType", u.BankAccType);
                comm.Parameters.AddWithValue("@bankAccNum", u.BankAccNum);
               
                rowsinserted = comm.ExecuteNonQuery();

                conn.Close();
            }
            catch (SqlException ex)
            {
                throw ex;
            }

            return rowsinserted;
        }
    }
}